package com.ppm.common.base.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author KwokChiKit
 * @date 2021/4/29 10:40
 * @Description 统一数据返回格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultDTO<T> extends BaseDTO {

  /**
   * 返回码
   */
  private Integer code;

  /**
   * 描述
   */
  private String msg;

  /**
   * 数据
   */
  private T data;

  public static ResultDTO requestSuccess() {
    return requestSuccess(null);
  }

  public static ResultDTO requestSuccess(Object data) {
    return new ResultDTO(200, null, data);
  }

  public static ResultDTO requestRejected(int code, String msg) {
    return new ResultDTO(501, msg, null);
  }

  public static ResultDTO requestDefault() {
    return new ResultDTO(200, "暂无数据", null);
  }

  public static <T> ResultDTO of(Integer code, String msg) {
    return new ResultDTO(code, msg, null);
  }

  public static <T> ResultDTO failed(String msg) {
    return of(500, msg);
  }

}
